package com.sgb.kjwl.view.ui.adapter.machine;

import android.content.Context;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemMyInquiryLeaseBinding;
import com.sgb.kjwl.model.entity.self.UserInquiryEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.List;

public class MyInquiryLeaseAdapter extends BaseRecycleAdapter<UserInquiryEntity> {

    private int type = 1;//0为收到，1为发起
    private String modelType = "4";//4:出租，5求租

    public void setType(int type) {
        this.type = type;
    }

    public void setModelType(String modelType) {
        this.modelType = modelType;
    }

    public MyInquiryLeaseAdapter(Context context, List<UserInquiryEntity> datas) {
        super(context, R.layout.item_my_inquiry_lease, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, UserInquiryEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        ItemMyInquiryLeaseBinding binding = (ItemMyInquiryLeaseBinding) holder.getmBinding();
        try {
            binding.tvTime.setText(DateUtils.stampToDate(entity.getCreateTime()));

            if ("4".equals(modelType)) {//出租
                // 模块的类型：1 机械租赁 ；2 设备租赁，3 车辆租赁； 4 房产租赁，5 土地租赁，6 工厂租赁
                if (entity.getMarkType() == 1) {
                    binding.tvTitleLabel.setText("机械租赁");
                } else if (entity.getMarkType() == 2) {
                    binding.tvTitleLabel.setText("设备租赁");
                } else if (entity.getMarkType() == 3) {
                    binding.tvTitleLabel.setText("车辆租赁");
                } else if (entity.getMarkType() == 4) {
                    binding.tvTitleLabel.setText("房产租赁");
                } else if (entity.getMarkType() == 5) {
                    binding.tvTitleLabel.setText("土地租赁");
                } else if (entity.getMarkType() == 6) {
                    binding.tvTitleLabel.setText("工厂租赁");
                } else if (entity.getMarkType() == 7) {
                    binding.tvTitleLabel.setText("农机租赁");
                }
            } else {//求租
                // 模块的类型：1 机械租赁 ；2 设备租赁，3 车辆租赁； 4 房产租赁，5 土地租赁，6 工厂租赁
                if (entity.getMarkType() == 1) {
                    binding.tvTitleLabel.setText("机械求租");
                } else if (entity.getMarkType() == 2) {
                    binding.tvTitleLabel.setText("设备求租");
                } else if (entity.getMarkType() == 3) {
                    binding.tvTitleLabel.setText("车辆求租");
                } else if (entity.getMarkType() == 4) {
                    binding.tvTitleLabel.setText("房产求租");
                } else if (entity.getMarkType() == 5) {
                    binding.tvTitleLabel.setText("土地求租");
                } else if (entity.getMarkType() == 6) {
                    binding.tvTitleLabel.setText("工厂求租");
                } else if (entity.getMarkType() == 7) {
                    binding.tvTitleLabel.setText("农机求租");
                }
            }

            //状态：1、已提问；5、已答复
            if (entity.getState() == 5) {
                binding.ivStatus.setImageResource(R.mipmap.ic_inquiry_lease_replied);
            } else {
                binding.ivStatus.setImageResource(R.mipmap.ic_inquiry_lease_unanswered);
            }

            if (type == 1) {
                binding.tvQuestionLabel.setText(Html.fromHtml("<font color='#666666'>疑问事项：</font>" + entity.getQuestion()));
            } else {
                binding.tvQuestionLabel.setText(Html.fromHtml("<font color='#666666'>函询内容：</font>" + entity.getQuestion()));
            }

        } catch (Exception ex) {
        }

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.detail(entity.getId());
                }
            }
        });

    }


    public interface onDetailListener {
        void detail(String id);
    }

    private onDetailListener listener;

    public void setOnDetailListener(onDetailListener listener) {
        this.listener = listener;
    }
}
